//
// Templet.h
//
// $Id: //base/include/Templet.h
//
// Library: base
// Package: base
// Module : Templet
// Author :	Jelin,doitsjz@163.com
// Date	  :	10/30/2012
// 
// Definition of the Templet class.
//
// Copyright (c) 2012-2012, iGuard.
//

#include "BaseHTTPResponse.h"
#include <sstream>

BaseHTTPResponse::BaseHTTPResponse()
{
}

	
BaseHTTPResponse::BaseHTTPResponse(HTTPStatus status, const std::string& reason):
	HTTPResponse(status,reason)
{
}


	
BaseHTTPResponse::BaseHTTPResponse(const std::string& version, HTTPStatus status, const std::string& reason):
	HTTPResponse(version,status,reason)
{
}

	
BaseHTTPResponse::BaseHTTPResponse(HTTPStatus status):
	HTTPResponse(status)
{
}


BaseHTTPResponse::BaseHTTPResponse(const std::string& version, HTTPStatus status):
	HTTPResponse(version,status)
{
}
BaseHTTPResponse::~BaseHTTPResponse()
{
}
void BaseHTTPResponse::setContentBody(const std::string& body)
{
	_body = body;
}
const std::string& BaseHTTPResponse::getContentBody() const
{
	return _body;
}
void BaseHTTPResponse::write(std::ostream& ostr) const
{
	HTTPResponse::write(ostr);
	if (!_body.empty())
		ostr << _body;// << "\r\n";
}

void BaseHTTPResponse::read(std::istream& istr)
{
	static const int eof = std::char_traits<char>::eof();
	HTTPResponse::read(istr);
	int ch = istr.get();
	while (ch != eof) { _body += (char) ch;ch = istr.get(); }
}
void BaseHTTPResponse::setMessage(const std::string& message)
{
	std::istringstream istr(message);
	read(istr);
}
void BaseHTTPResponse::getMessage(std::string& message)
{
	std::ostringstream ostr;
	write(ostr);
	message = ostr.str();
}